#pragma once
#include "Http.h"
#include "BaseHttpRequest.h"

class FBodyHttpRequest : public FBaseHttpRequest
{
public:
	FBodyHttpRequest();
	virtual ~FBodyHttpRequest();

public:
	int32 GetRemainBytes() const;
	void FixBodyStage();

public:
	void Initilize(int32 ID, const FString &Url, int32 BeginRange, int32 EndRange, const FString &LastModify);

	virtual const TArray<uint8>* GetData() const override;

	virtual int32 GetRecvBytes() const;

	virtual int32 GetBeginRange() const { return mBeginRange; }
	virtual int32 GetEndRange() const { return mEndRange; }

public:
	virtual bool CanRetry() const override;
	virtual bool Retry() override;

public:
	virtual bool NeedDeserialized() const override;

	virtual void Serialized(FMemoryWriter &Write) override;
	virtual void Deserialized(FBufferReader &Reader) override;

public:
	void SetLastModify(const FString &LastModify);

protected:
	virtual void InitHeader() override;
	virtual void UpdateStage(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully) override;

protected:
	virtual void CompleteCallback(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully) override;
	virtual void HeaderReceivedCallback(FHttpRequestPtr Request, const FString& HeaderName, const FString& NewHeaderValue) override;
	virtual void ProgressCallback(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) override;
	virtual void WillRetryCallback(FHttpRequestPtr Request, FHttpResponsePtr Response, float SecondsToRetry) override;

private:
	int32 mBeginRange;
	int32 mEndRange;
	FString mLastModify;

	int32 mRecvBytesThisRequest;
	TArray<uint8> mContentData;
};
